package com.fc.advbox.controller.api;

import com.fc.advbox.utils.R;
import com.fc.advbox.utils.annotation.IgnoreAuth;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.websocket.server.PathParam;

/**
 * Health Check
 *
 * @author Charles
 */
@RestController
@RequestMapping("/api")
@Api(tags={"健康检查 API"})
public class HealthCheckController {

    @ApiOperation(value = "Health check with Json",
            notes = "This API is used to check server status is alive or not. <p>" +
                    "Other detail info: <ul>" +
                    "<li><i>Required permission</i>: resource=\"NAMESPACE:{namespace}:ACTIVITY\", action=1 (CREATE)</li>" +
                    "<li><i>Returns</i>: i am alive</li>" +
                    "</ul>",
            response = R.class,
            httpMethod = "GET",
            consumes = "application/json",
            produces = "application/json",
            code = 201
    )
    @IgnoreAuth
    @RequestMapping("/health_check/json")
    @ResponseBody
    public R health_json(){
        return R.ok("I am alive");
    }

    @ApiOperation(value = "Health check with Json",
            notes = "This API is used to check server status is alive or not. <p>" +
                    "Other detail info: <ul>" +
                    "<li><i>Returns</i>: i am alive</li>" +
                    "</ul>",
            response = R.class,
            httpMethod = "GET",
            consumes = "application/text",
            produces = "application/text",
            code = 201
    )
    @IgnoreAuth
    @RequestMapping("/health_check/plain")
    @ResponseBody
    public String health_plain(){
        return "I am alive";
    }

    @ApiOperation(value = "Health check with Json",
            notes = "This API is used to check server status is alive or not. <p>" +
                    "Other detail info: <ul>" +
                    "<li><i>Returns</i>: i am alive</li>" +
                    "</ul>",
            response = R.class,
            httpMethod = "GET",
            consumes = "application/json",
            produces = "application/json",
            code = 201
    )
    @IgnoreAuth
    @RequestMapping("/health_check/namespace/{namespace}")
    @ResponseBody
    public R health_plain(
            @ApiParam(name="namespace", required=true) @PathParam("namespace") String namespace){
        return R.ok("I am alive");
    }
}
